package com.baidu.oa;

import redis.clients.jedis.Jedis;

import java.util.List;

/**
 * 论坛项目 帖子相关操作
 * string 数据结构
 *
 * redis
 *
 */
public class Demo01 {
    public static void main(String[] args) {
        Jedis jedis = new Jedis("192.168.133.118",6379);
        //用户发表帖子
        Long isOk = jedis.msetnx("topic:1:title", "如何买彩票",
                "topic:1:content", "1.你要有钱 2.你要会投胎",
                "topic:1:author", "ztf",
                "topic:1:time", "2020-11-25 08:08:08");
        //查看发表的结果
        System.out.println("发布帖子的结果："+isOk);
        //查看帖子
        List<String> topicList = jedis.mget("topic:1:title", "topic:1:content",
                "topic:1:author", "topic:1:time");
        System.out.println("查看帖子：" + topicList);

        System.out.println("=========================================================");
        //修改帖子
        String isUpdateOk = jedis.mset("topic:1:title", "标题改为:如何投胎",
                "topic:1:content", "内容改为：1.2.","topic:1:time","当前时间");
        System.out.println("修改的结果：" + isUpdateOk);

        topicList = jedis.mget("topic:1:title", "topic:1:content",
                "topic:1:author", "topic:1:time");
        System.out.println("再次查看：" + topicList);
        if(jedis!=null){
            jedis.close();
        }
    }
}
